/**
 * Created by Administrator on 2017/6/21 0021.
 */
var F_Additional_Entrance = {

    _init: function () {
        console.log("F_Additional_Entrance");

        if (B_Login._checkUpdate(), M_HeadFoot._headShow(1), "demo" != M_Init._controller && B_User._isDemoUser()) B_Login._openLogin("background"); else {
            switch (M_Init._clean(), M_Init._controller) {
                case"demo":
                    M_Init._api.innerOperationNewUser = "demoInnerOperationNewUser";
                    break;
                default:
                    M_Init._api.innerOperationNewUser = "innerOperationNewUser"
            }
            M_Init._dateCache.begin = M_Init._dateChoose.begin, M_Init._dateCache.end = M_Init._dateChoose.end, M_Common._getOrderGame("additional", "", "1-2-1"),

                B_Date._chooseSection({
                autoCommit: !1,
                todayValid: !1
            }, 1, M_Init._dateChoose.begin, M_Init._dateChoose.end, function (a, t) {
                a == M_Init._dateCache.begin && M_Init._dateCache.end == t || (M_Init._dateCache.begin = a, M_Init._dateCache.end = t, F_Additional_Info._getInfo()
                )
            })
        }
    }
}, F_Additional_Info = {
    _init: [{
        type: "togetherTabAvg",
        name: "新增玩家走势",
        tab: ["新增人数", "首日付费率"],
        tips: [{}, {position: "second", content: ["当日新增加的玩家人数", "当日新增玩家中在新增日即付费的占全部新增玩家的比例"]}]
    }, {
        type: "switch",
        name: "首日游戏时长分布",
        tab: [],
        tips: [{position: "first", content: "所选日期新增玩家第一日游戏的时长分布"}]
    }, {
        type: "regionTab",
        name: "地区分布",
        tab: ["中国地区", "全球地区"],
        tips: [{}, {position: "second", content: ["所选日期新增玩家的地区分布情况", "所选日期新增玩家的地区分布情况"]}]
    }],
    _avg: [[[{label: "AVG：", name: "平均每日新增玩家数", key: "avg_new_user", unit: ""}], [{
        label: "AVG：",
        name: "平均每日新增玩家的首日付费率",
        key: "avg_pay_rate",
        unit: "%"
    }]]],
    _port: [[[{name: "新增玩家", key: "y_axis_newlogin_num"}], [{
        name: "首日付费率",
        key: "y_axis_pay_rate"
    }]], [[{name: "首日游戏时长", key: "new_user_oltime_distri"}]], [[{
        name: "国内地区分布",
        key: "area_distri|china"
    }], [{name: "国际地区分布", key: "area_distri|global"}]]],
    _domInit: function () {
        M_Inside._htmlChartTable($("#ct_main_area"), F_Additional_Info._init), M_Inside._downloadCsv(), F_Additional_Info._getInfo()
    },
    _getInfo: function () {
        for (var a = M_Init._dateCache.begin, t = M_Init._dateCache.end, e = [], n = 0; n < F_Additional_Info._init.length; n++)
            e.push("bs_chart_" + n + "_0");

        console.log("eeee is:",e);

        var i = {};
        i.start_date = a, i.end_date = t, i.game_id = M_Init._gameId, i = B_Common._postData(i), B_Port._ajax(M_Init._api.innerOperationNewUser, "post", !0, i, function () {
            for (var a = 0; a < e.length; a++)$("#" + e[a]).html(B_Pre._loading())
        }, function () {
            for (var a = 0; a < e.length; a++)$("#" + e[a]).html("")
        }, function (a, t) {
            if (a) {
                M_Init._dataCache.data = a;
                for (var e = 0; e < F_Additional_Info._init.length; e++)if (F_Additional_Info._init[e].tab.length > 0) {
                    M_Init._dataCache["position_" + e] || (M_Init._dataCache["position_" + e] = 0);
                    for (var n = 0; n < F_Additional_Info._init[e].tab.length; n++)if (M_Init._dataCache["position_" + e] == n) {
                        F_Additional_Info._chartHtml(e, n), M_Inside._chartTableIcon(F_Additional_Info._init[e].type, e, n);
                        break
                    }
                    M_Inside._tabChangePerChart(e, F_Additional_Info._init[e].type, "additional")
                } else F_Additional_Info._chartHtml(e, "0"), M_Inside._chartTableIcon(F_Additional_Info._init[e].type, e, "0")
            }
        }, function (a, t, n) {
            for (var i = 0; i < e.length; i++)$("#" + e[i]).html(B_Pre._empty(t))
        })
    },
    _chartHtml: function (a, t) {

        M_Init._dataCache["position_" + a] = t;
        var e = M_Init._dataCache.data, n = {x_axis: [], y_axis: [], yFormat: ""}, i = {}, _ = 50, o = "";
        switch (a + "") {
            case"0":
                switch (n.xFormatDate = !0, t + "") {
                    case"0":
                        n.yFormat = "", n.tooltip = {num: 1, unit: "人"}, o = "人";
                        break;
                    case"1":
                        n.yFormat = "%", n.tooltip = {num: 1, unit: "%"}, o = "%"
                }
                break;
            case"1":
            case"2":
                n.tooltip = {num: 1, unit: "人"}
        }
        for (var d = 0; d < F_Additional_Info._port[a][t].length; d++) {
            var s = F_Additional_Info._port[a][t][d].key.split("|"), r = F_Additional_Info._port[a][t][d].name;
            if (1 == a) {
                if (_ = 20, i = {head: ["时长", "新增玩家(人)", "玩家占比"], body: []}, e[s[0]]) {
                    for (var l = e[s[0]], h = [], c = 0; c < l.length; c++)l[c].oltime_classify = l[c].oltime_classify.replace("&gt;", ">"), l[c].oltime_classify = l[c].oltime_classify.replace("&lt;", "<"), n.x_axis.push(l[c].oltime_classify), h.push(l[c].user_num), i.body[c] || (i.body[c] = [l[c].oltime_classify]), i.body[c].push(l[c].user_num), i.body[c].push(l[c].user_rate + "%");
                    n.y_axis.push({name: r, data: h})
                }
            } else if (2 == a) {
                if (_ = 20, i = {head: ["地区", "新增玩家(人)", "玩家占比"], body: []}, e[s[0]] && e[s[0]][s[1]]) {
                    for (var l = e[s[0]][s[1]], h = [], c = 0; c < l.length; c++)n.x_axis.push(l[c].area_classify), h.push(l[c].user_num), i.body[c] || (i.body[c] = [l[c].area_classify]), i.body[c].push(l[c].user_num), i.body[c].push(l[c].user_rate + "%");
                    n.y_axis.push({name: r, data: h})
                }
                t = 0
            } else if (_ = 50, i = {
                    head: ["日期"],
                    body: []
                }, n.x_axis = e.x_axis, "%" != o ? i.head.push(r + "(" + o + ")") : i.head.push(r), e[s[0]]) {
                for (var l = e[s[0]], c = 0; c < l.length; c++)i.body[c] || (i.body[c] = [e.x_axis[c]]), "%" != o ? i.body[c].push(l[c]) : i.body[c].push(l[c] + o);
                n.y_axis.push({name: r, data: l})
            }
        }
        if (F_Additional_Info._avg[a] && F_Additional_Info._avg[a][t]) {
            for (var I = "", f = F_Additional_Info._avg[a][t], m = 0; m < f.length; m++)f[m].label && (I += "<span>" + f[m].label + "</span>"), I += "<span>" + f[m].name + "<b>", s = f[m].key.split("|"), e[s[0]] && (I += e[s[0]]), I += f[m].unit + "</b></span>";
            M_Inside._avgHtml(a + "_0", I)
        }
        i.name = M_Inside._tableName(F_Additional_Info._init, a, t, M_Init._dateCache.begin, M_Init._dateCache.end), t = 0, M_Init._dataCache[a + "_" + t] = i,
            M_Inside_Chart._chartData(_, "bs_chart_" + a + "_" + t, n), M_Inside._tableHtml(1, a + "_" + t)
    }
};